package com.cys.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cys.dm.dao.order.DmOrderLinkUserDao;
import com.cys.dm.entity.order.DmOrder;
import com.cys.dm.entity.order.DmOrderLinkUser;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author blue_t
 * @date 2020-12-23 17:34
 */
@RestController
public class DmOrderLinkUserService {
    @Resource
    private DmOrderLinkUserDao dmOrderLinkUserDao;

    /**
     * 删除订单联系人
     * @param dmOrderLinkUser
     * @return
     */
    @PostMapping(path = {"deleteOrderLinkUser"})
    public Integer deleteOrderLinkUser(@RequestBody DmOrderLinkUser dmOrderLinkUser){
        QueryWrapper<DmOrderLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderId",dmOrderLinkUser.getOrderId());
        return dmOrderLinkUserDao.delete(queryWrapper);
    }

    /**
     * 添加订单常用联系人
     * @param dmOrderLinkUser 订单常用联系人
     * @return
     */
    @PostMapping(path = {"addOrderLinkUser"})
    public Integer addOrderLinkUser(@RequestBody DmOrderLinkUser dmOrderLinkUser){
        return dmOrderLinkUserDao.insert(dmOrderLinkUser);
    }

    /**
     * 根据订单ID查询订单联系人
     * @param orderId
     * @return
     */
    @PostMapping(path = {"findOrderLinkUserByOrderId/{orderId}"})
    public List<DmOrderLinkUser> findOrderLinkUserByOrderId(@PathVariable("orderId")Long orderId){
        QueryWrapper<DmOrderLinkUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("orderId",orderId);
        return dmOrderLinkUserDao.selectList(queryWrapper);
    }

}
